// void, Obj This

Building this, build;
str names;

Sleep(180+rand(GetConst("RandTimeStart"))+GetConst("AddTimeStart"));

this = This.AsBuilding();

while (!.IsValid)
	Sleep(10000);        

if(.IsValid){
	if(.IsHeirOf("BaseTownhall")){
        EnvWriteInt(.player, "RACE", .race);
    }

	if(.name == ""){
	
        names = "B_"+.class+"_"+.player+.race+rand(99)+rand(99);
		build = GetNamedObj(names).obj.AsBuilding;
		if(!build.IsValid){
			.SetName("");       
			.SetName(names);
		} else {
			names = "B_"+.class+"_"+.player+.race+rand(99)+rand(99);
			.SetName("");       
			.SetName(names);
		}  
    } else {
		Sleep(600*60000);
	}
}

//while(.IsValid) { Sleep(1000); } 



